<template>
    <van-pull-refresh 
        v-model="isLoading" 
        @refresh="onRefresh">
          <van-list
              v-model="loading"
              :finished="finished"
              finished-text="没有更多了"
              @load="onLoad"
              :immediate-check="false"  
            >
              <slot></slot>
          </van-list>
    </van-pull-refresh>
</template>


<script>
export default {
  props:['refresh','loaddata'],
  data(){
    return {
      isLoading: false,
      loading: false,  // 是否正在加载中
      finished: false,  // 数据见底了
    }
  },
  methods:{
    onLoad(){
      
      this.loaddata(
        ()=>{
          this.loading = false;
          this.$toast("加载成功.")
      },()=>{
          this.finished = true; 
          this.$toast("没有更多数据了.")
      })
    },
    onRefresh(){
        this.isLoading = true;
        this.refresh();
        setTimeout(() => {
          this.$toast('下拉刷新成功');
          this.isLoading = false;
        }, 1000);
    }
  }
}
</script>


<style lang="scss" scoped>
.van-list{
  // padding-bottom:50px;
}
</style>
